<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的社群</title>
    <meta name="viewport" content=" initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
    <script src="{$Think.config.RESOURCEURL}wx_assets/personCenter/js/mediaQuery.min.js{$Think.config.RESOURCE_VER}"></script>
    <script type='text/javascript' src='{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js'></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.alert.js" type="text/javascript"></script>
    <script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}"></script>
    <style>
        .rDialog-wrap {
            font-size: .36rem;
        }
        .rDialog-time .rDialog-content {
            padding: 20px 0;
        }
        article {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            width: 100%;
            background: #efeff4;
            height: 100%;
            font-size: 0;
        }
        h3 {
            font-size: .3rem;
            height: .75rem;
            line-height: .75rem;
            color: #fff;
            background: #ff9900 ;
            text-align: center;
            position: relative;
        }
        h3 a{
            display: inline-block;
            position: absolute;
            height: .75rem;
            width: .7rem;
            left: 0;
            background: url({$Think.config.RESOURCEURL}wx_assets/commune/images/new_sj.png{$Think.config.RESOURCE_VER}) center center no-repeat;
            background-size: .17rem .32rem;
        }
        form {
            font-size: 0;
        }
        form p {
            margin-top: .2rem;
            height: .7rem;
            line-height: .7rem;
            background-color: #fff;
            padding-left: .2rem;
        }
        label {
            font-size: .3rem;
            color: #2c2c2c;
        }
        input {
            font-size: .3rem;
            text-align: center;
            width: 70%;
        }
        .mt1 {
            margin-top: 1rem;
        }
        div button {
            font-size: .3rem;
            color: #fff;
            border: none;
            background-color: #ff9900;
            height: .7rem;
            line-height: .7rem;
            width: 2rem;
            text-align: center;
            margin-left: .8rem;
            border-radius: .05rem;
        }
        div.mt1 p{
            margin-top: .5rem;
            font-size: .24rem;
            text-align: center;
            color: #666;
        }
        div.mt1 p button {
            width: 4.8rem;
            margin-left: 0;
        }
    </style>
</head>
<body>
   <article>
       <h3>
           <a href="javascript:history.go(-1);"></a>
           社群基本信息
       </h3>
       <form action="" id="new">
           <p>
               <label for="name">社群名称 :</label>
               <input type="text" placeholder="请填写社群名称" id="name" value="{$results.groupName}">
           </p>
           <p>
               <label for="number">社群人数 :</label>
               <input type="text" placeholder="请填写社群人数" id="number" value="{$results.countNumber}">
           </p>
       </form>
       <div class="mt1">
           <button id="BtnSave">保存</button>
           <button onclick="history.go(-1);">取消</button>
           <if condition="$results.id != '' ">
           <p id="del"><button>删除本群</button></p>
           </if>
       </div>
   </article>
   <script>
       var baseUrl = '{$Think.config.SERVER_HOST}';
       var burl = "{$Think.config.SERVER_HOST}call.json?customerId={$customerId}";
       var gid = '{$results.id}';
       $("#BtnSave").click(Savefn);
       function Savefn(){
           var p = $.util.getParamAsObject();
           var name = $("#name").val();
           var number = $("#number").val();
           if(name =="" && number ==""){
               $.util.alert("社群名称和社群人数不能为空");
           }
           else if( name==""){
               $.util.alert("社群名称不能为空");
           }
           else if( number ==""){
               $.util.alert("社群人数不能为空");
           }
           else if(!/^[0-9]*$/.test(number)){
               $.util.alert("社群人数必须为数字");
           }
           else if( name.length > 15){
               $.util.alert("社群名称最多15字");
           }
       else {
               $.util.pageLoading.show("正在保存...");
               if(p){
                   $.ajax({
                       type: 'get',
                       url: burl,
                       dataType: 'json',
                       data:{
                           'module':"commune",
                           "method":"communeGroupAdd",
                           "params":JSON.stringify({"groupname":name,"groupcount":number,"id": p.id||0})
                       },
                       success: function(data){
                           $.util.pageLoading.hide();
                           $.util.alert("保存成功");
                           location.href= baseUrl+'call.html?customerId={$customerId}&module=commune&method=communeGroupView';

                       },
                       error: function(xhr, type){
//            alert('Ajax error!')
                       }
                   })
               }
               else {
                   $.ajax({
                       type: 'get',
                       url: burl,
                       dataType: 'json',
                       data:{
                           'module':"commune",
                           "method":"communeGroupAdd",
                           "params":JSON.stringify({"groupname":name,"groupcount":number})
                       },
                       success: function(data){
                           $.util.pageLoading.hide();
                           $.util.alert("保存成功");
                       },
                       complete:function(){
                           location.href= baseUrl+'call.html?customerId={$customerId}&module=commune&method=communeGroupView';
                       },
                       error: function(xhr, type){
//            alert('Ajax error!')
                       }
                   })
               }
           }
       }

       $("#del button").click(function(){
           $.util.ok("确定要删除吗？",function(){
               $.req.get("call.json?customerId={$customerId}&module=commune&method=communeDeleteGroup",{
                   params:{
                       "gid":gid
                   }
               },function(){
                   $.util.alert("已删除");
                       location.href= baseUrl+'call.html?customerId={$customerId}&module=commune&method=communeGroupView';
               });
           });
       })
   </script>
</body>
</html>